﻿namespace AnimalExercise
{
    using System;

    public class MainAnimalExercise
    {
        //// 1.2.17.03. Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods.
        //// Dogs, frogs and cats are Animals. All animals can produce sound (specified by the ISound interface).
        //// Kittens and tomcats are cats. All animals are described by age, name and sex. Kittens can be only female and
        //// tomcats can be only male. Each animal produces a specific sound. Create arrays of different kinds of
        //// animals and calculate the average age of each kind of animal using a static method (you may use LINQ).

        public static float AverageAge(Animal[] collectionOfAnimals)
        {
            float holeAnimalExperiene = 0;
            foreach (var animal in collectionOfAnimals)
            {
                holeAnimalExperiene += animal.Age;
            }

            return holeAnimalExperiene / collectionOfAnimals.Length;
        }

        private static void Main()
        {
            Dog[] dogs = { new Dog("Sharo", 21, "male"), new Dog("Lasi", 18, "male") };
            Console.WriteLine(AverageAge(dogs));
            dogs[0].ReleaseSound();

            Animal[] zoo = { new Cat("Tom", 11, "male"), new Frog("Kurmit", 8, "male"), new Kitten("Magi", 3) };
            Console.WriteLine(AverageAge(zoo));
            zoo[0].ReleaseSound();
            zoo[1].ReleaseSound();
            zoo[2].ReleaseSound();
        }
    }
}